package com.scarrone.gmtools.ui;
import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import javax.swing.JList;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import java.awt.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.scarrone.gmtools.Data;
import com.scarrone.gmtools.PlotObject;
import com.scarrone.sqlite.ResultArrayStruct;
import com.scarrone.sqlite.SQLiteHander;
import org.sqlite.*;
public class MainUI extends JFrame{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JList jList = null;
private JLabel PlotItemsLbl = null;
private JButton addPlotItem = null;
private JLabel Characters = null;
private JList CharacterList = null;
private JButton AddCharButton = null;
private JTextPane PlotLog = null;
private JButton LoadLog = null;
private JButton SaveLog = null;
DefaultListModel Plotmodel = new DefaultListModel();
/**
* This is the default constructor
*/
public MainUI() {
super();
initialize();
final addPlotDialog PlotDialog = new addPlotDialog();
addPlotItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//addPlotDialog PlotDialog = new addPlotDialog();
PlotDialog.setVisible(true);
}
});
addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
public void windowGainedFocus(WindowEvent e) {
// TODO Auto-generated method stub
LoadPlots();
}
});
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(1200, 800);
this.setContentPane(getJContentPane());
this.setTitle("GM Tools");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
Characters = new JLabel();
Characters.setBounds(new Rectangle(313, 15, 79, 16));
Characters.setText("Characters");
PlotItemsLbl = new JLabel();
PlotItemsLbl.setBounds(new Rectangle(28, 15, 71, 16));
PlotItemsLbl.setText("Plot Items");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJList(), null);
jContentPane.add(PlotItemsLbl, null);
jContentPane.add(getAddPlotItem(), null);
jContentPane.add(Characters, null);
jContentPane.add(getCharacterList(), null);
jContentPane.add(getAddCharButton(), null);
jContentPane.add(getPlotLog(), null);
jContentPane.add(getLoadLog(), null);
jContentPane.add(getSaveLog(), null);
}
return jContentPane;
}
/**
* This method initializes jList
*
* @return javax.swing.JList
*/
private JList getJList() {
if (jList == null) {
jList = new JList();
jList.setBounds(new Rectangle(26, 37, 255, 285));
}
return jList;
}
/**
* This method initializes addPlotItem
*
* @return javax.swing.JButton
*/
private JButton getAddPlotItem() {
if (addPlotItem == null) {
addPlotItem = new JButton();
addPlotItem.setBounds(new Rectangle(63, 338, 115, 29));
addPlotItem.setText("Add Plot Item");
}
return addPlotItem;
}
/**
* This method initializes CharacterList
*
* @return javax.swing.JList
*/
private JList getCharacterList() {
if (CharacterList == null) {
CharacterList = new JList();
CharacterList.setBounds(new Rectangle(313, 40, 274, 280));
}
return CharacterList;
}
/**
* This method initializes AddCharButton
*
* @return javax.swing.JButton
*/
private JButton getAddCharButton() {
if (AddCharButton == null) {
AddCharButton = new JButton();
AddCharButton.setBounds(new Rectangle(380, 339, 127, 29));
AddCharButton.setText("Add Character");
}
return AddCharButton;
}
/**
* This method initializes PlotLog
*
* @return javax.swing.JTextPane
*/
private JTextPane getPlotLog() {
if (PlotLog == null) {
PlotLog = new JTextPane();
PlotLog.setBounds(new Rectangle(29, 381, 951, 370));
}
return PlotLog;
}
/**
* This method initializes LoadLog
*
* @return javax.swing.JButton
*/
private JButton getLoadLog() {
if (LoadLog == null) {
LoadLog = new JButton();
LoadLog.setBounds(new Rectangle(990, 450, 93, 29));
LoadLog.setText("Load Log");
}
return LoadLog;
}
/**
* This method initializes SaveLog
*
* @return javax.swing.JButton
*/
private JButton getSaveLog() {
if (SaveLog == null) {
SaveLog = new JButton();
SaveLog.setBounds(new Rectangle(991, 494, 90, 29));
SaveLog.setText("Save Log");
}
return SaveLog;
}
private void populatePlotList(){
Plotmodel.clear();
this.jList.setModel(Plotmodel);
this.jList.removeAll();
for(int i = 0; i < Data.PlotElements.size(); i++){
Plotmodel.addElement(Data.PlotElements.get(i).Title);
}
this.jList.setModel(Plotmodel);
}
private void LoadPlots(){
Data.purgePlots();
//SQLite db = null;
SQLiteHander SQL = new SQLiteHander();
SQL.executeQuery("SELECT Title, Desc FROM plotElements");
ResultArrayStruct result = SQL.getResultStruct();
System.out.println(result.getColCount());
for(ArrayList<String> row : result.getRows()){
Data.PlotElements.add(new PlotObject(row.get(0), row.get(1)));
}
this.populatePlotList();
}
} // @jve:decl-index=0:visual-constraint="6,3"